<template>
  <el-radio-group ref="radioData" :value="value" clearable filterable :disabled="isDisabled" :placeholder="placeholder" @change="radioChange" @input="change($event)">
    <span v-for="(item, index) in radioList" :key="item.code">
      <el-radio :label="item.code" :value="item.code" style="width:180px">{{ item.text }}</el-radio>
      <span v-if="(index + 1) % 5 == 0 "><br></span>+
    </span>
  </el-radio-group>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'CommonRadio',
  props: {
    name: {
      type: String,
      default: ''
    },
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    hiddenValues: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      radioList: [],
      placeholder: this.placetext,
      isDisabled: !!this.disabled,
      hideValueList: this.hiddenValues ? this.hiddenValues.split(',') : []
    }
  },
  computed: {
    imageUrl() {
      return this.value
    }
  },
  watch: {
    disabled: function(val) {
      this.isDisabled = !!val;
    }
  },
  mounted: function() {
    this.getData();
  },
  methods: {
    getData: function() {
      var _this = this;
      request({
        url: `/common/dict/getDictDataByName/${this.name}`
      }).then(res => {
        if (_this.hideValueList) {
          _this.radioList = res.data.filter(function(item) {
            var isHide = false;
            for (var i = 0; i < _this.hideValueList.length; i++) {
              if (item.code === _this.hideValueList[i]) {
                isHide = true
              }
            }
            return !isHide;
          });
        } else {
          _this.radioList = res.data;
        }
      })
    },
    radioChange: function(value) {
      this.$emit('choose', value);
      this.$emit('radio-change', value);
    },
    change: function(value) {
      var self = this;
      self.$emit('input', value);
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
